import pymysql

# 创建连接
connection = pymysql.connect(host='your_host',
                              user='your_username',
                              password='your_password',
                              db='your_database')

# 创建游标
cursor = connection.cursor()

# 执行查询
try:
    cursor.execute('SELECT * FROM your_table')
except Exception as e:
    print(f"Error executing query: {e}")

# 获取结果
results = cursor.fetchall()
for row in results:
    print(row)

# 关闭连接
cursor.close()
connection.close()